package cn.com.jslh.boarpro.util.adapter;

import android.content.Intent;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import cn.com.jslh.boarpro.R;
import cn.com.jslh.boarpro.main.entity.NewsWarnEnity;
import cn.com.jslh.boarpro.main.view.WarnResultActivity;
import cn.com.jslh.boarpro.util.RecycleViewItemDecoration;

/**
 * Created by lenovo on 2018/3/26.
 */

public class NewsWarnAadpter extends BaseRecycleAdapter<NewsWarnEnity> {

    public NewsWarnAadpter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, NewsWarnEnity item) {
        RecyclerView recyclerView=helper.getView(R.id.recycle_news_warn_item);
        NewsWarnTitleAdapter adapter=new NewsWarnTitleAdapter(R.layout.news_warn_title_item);


        helper.setText(R.id.tv_news_warn_item,item.getName());

        adapter.addData(item.getList(),true);
        adapter.notifyDataSetChanged();
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(mContext);
        recyclerView.setLayoutManager(linearLayoutManager);
        recyclerView.addItemDecoration(new RecycleViewItemDecoration());
        recyclerView.setAdapter(adapter);


        Log.d("打印type",helper.getItemViewType()+"zxx");
        if(helper.getItemViewType()==0){
            helper.setBackgroundColor(R.id.tv_news_warn_item,mContext.getResources().getColor(R.color.red_title_bg));
        }else {
            helper.setBackgroundColor(R.id.tv_news_warn_item,mContext.getResources().getColor(R.color.yellow_title_bg));
        }

        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                NewsWarnEnity info= (NewsWarnEnity) adapter.getItem(position);
                if(info.getEnable()==1){
                    Intent intent=new Intent(mContext, WarnResultActivity.class);
                    intent.putExtra("info",info);
                    mContext.startActivity(intent);
                }

            }
        });

    }

    @Override
    public int getItemCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int position) {
        if(position%2==0){
            return 0;
        }else {
            return 1;
        }

    }
}
